/**
 * Created by winaya on 2016/11/5.
 */
if (!$.fn.dataType) {
    $.fn.dataType = {};
}
$.fn.dataType.config = {
    "int": {char: /\d/, text: /0|[1-9]\d*/},
    "float": {char: /\d|\./, text: /^(0|[1-9]\d*)(\.\d*)?$/}
};
$(document).ready(function () {
    var events = {};
    $.each($.fn.dataType.config, function (i, n) {
        events[i] = function (e) {
            var char = String.fromCharCode(e.keyCode);
            return n.char.test(char) && n.text.test($(this).val() + char);
        };
    });
    $.each($("input[data-type]"), function (i, n) {
        var dataType = $(n).attr("data-type");
        dataType = dataType ? dataType : $(this).attr("dataType");
        var event = events[dataType];
        if (event) {
            $(n).keypress(function (e) {
                return event.call(this, e);
            });
        }
    });
});